package cn.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import cn.pojo.Token;
import cn.util.DBUtil;

public class TokenDaoImpl extends DBUtil implements TokenDao {

    @Override
    public Token getTokenByMid(Integer mid) {
        Connection ct = getConnection();
        PreparedStatement ps = null;
        ResultSet st = null;
        String sql = "Select * from token where mid = ? ;";
        try {
            ps = ct.prepareStatement(sql);
            ps.setObject(1, mid);
            st = ps.executeQuery();
            Token token = null;
            while (st.next()) {
                token = new Token();
                token.setCreateTime(st.getDate("createTime"));
                token.setId(st.getInt("id"));
                token.setMid(st.getInt("mid"));
                token.setToken(st.getString("token"));
            }
            return token;
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            release(ct, ps, st);
        }
        return null;
    }
}
